//
//  LSRevampPasswardVController.m
//  LookScore
//
//  Created by wr on 2017/12/16.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSRevampPasswardVController.h"
#import "LSNavigationViewController.h"
#import "LSLoginVController.h"
@interface LSRevampPasswardVController ()
@property (weak, nonatomic) IBOutlet UITextField *oldPasswardTF;

@property (weak, nonatomic) IBOutlet UITextField *rePasswardTF;

@property (weak, nonatomic) IBOutlet UIButton *sureBu;
@property (weak, nonatomic) IBOutlet UIButton *isCheckOldPswBu;
@property (weak, nonatomic) IBOutlet UIButton *isCheckRePswBu;

@end

@implementation LSRevampPasswardVController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"修改密码";
    self.view.backgroundColor=[UIColor whiteColor];
    
    self.oldPasswardTF.keyboardType = UIKeyboardTypeASCIICapable;
    self.rePasswardTF.keyboardType = UIKeyboardTypeASCIICapable;
    
    self.oldPasswardTF.secureTextEntry = YES;
    self.rePasswardTF.secureTextEntry = YES;
    
    [self.sureBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor7ec5fd] forState:UIControlStateNormal];
    [self.sureBu setBackgroundImage:[CommonClass getImageWithBgColor:LSNavMainColor] forState:UIControlStateHighlighted];
}
#pragma mark 🔥 确认修改
- (IBAction)sureRevampEvvent:(UIButton *)sender {
    
    
    if (_oldPasswardTF.text.length == 0) {
        [MBProgressHUD showOnlyMessage:@"请输入旧密码" afterDelay:1.5f];
    }
    else if (_rePasswardTF.text.length<6 || _rePasswardTF.text.length > 15){
        [MBProgressHUD showOnlyMessage:@"请输入6-15位的密码" afterDelay:1.5f];
        
    }
    else if ([self isEmpty:_rePasswardTF.text]) {
        [MBProgressHUD showOnlyMessage:@"密码中不能含有空格字符" afterDelay:1.5f];
    }
    else if ([_rePasswardTF.text isEqualToString:_oldPasswardTF.text]){
        [MBProgressHUD showOnlyMessage:@"新密码与旧密码一致，请重新输入新密码" afterDelay:1.5f];
    }
    else if (_rePasswardTF.text.length >= 6 && _rePasswardTF.text.length <= 15 && _oldPasswardTF.text != 0) {
        [LSHttpEnclosureTool POST:LSUserChangePwd parameters:@{@"oldpwd":_oldPasswardTF.text,@"pwd":_rePasswardTF.text,@"cid":[LSAccountArchive account].Cid} resBlock:^(id responseObject) {
            if (responseObject) {
                [LSAccountArchive logout];
                [notifiCenter postNotificationName:@"ISLOGIN" object:nil];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passwordString"];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"select"];
                [self dismissRootViewControllerLevel:1];
                
//                if (self.PassWordChangedBlock) {
//                    self.PassWordChangedBlock();
//                }
            }
        }];
    }
}
- (IBAction)isOpenOldPsw:(UIButton *)sender {
    sender.selected=!sender.selected;
    self.oldPasswardTF.secureTextEntry = sender.selected;
}
- (IBAction)isOpenRePsw:(UIButton *)sender {
    sender.selected=!sender.selected;
    self.rePasswardTF.secureTextEntry = sender.selected;
}

-(BOOL)isEmpty:(NSString *) str {
    NSRange range = [str rangeOfString:@" "];
    if (range.location != NSNotFound) {
        return  YES; //yes代表包含空格
    }else {
        return  NO;  //反之
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
